<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 统计字符串中每个字符的个数？
var str = 'abcdacbabcbababcbabcabd'

// 结果
// { a: 出现次数， b: 出现次数, ...} -->
    <script>
      var str = "abcdacbabcbababcbabcabd";
      var obj = {};
      for (i = 0; i < str.length; i++) {
        var x = str.charAt(i);

        if (obj[x] == undefined) {
          obj[x] = 1;
        } else {
          obj[x]++;
        }
      }
      console.log(obj);
    </script>
  </body>
</html>
